home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / strlib.zip / STRCPACK.C < prev    next >
Text File  |  1993-01-04  |  1KB  |  40 lines

  1.  
  2. /*  File   : strcpack.c
  3.     Author : Richard A. O'Keefe.
  4.     Updated: 20 April 1984
  5.     Defines: strcpack()
  6.  
  7.     strcpack(dst, src, set, c)
  8.     copies characters from src to dst, stopping when it finds a NUL.  If
  9.     c is NUL, characters not in the set are not copied to dst.  If c  is
  10.     not  NUL,  sequences  of  characters  not in the set are copied as a
  11.     single c. strcpack is to strpack as strcspn is to strspn.  If your C
  12.     compiler is happy with register _char_, change the declaration of c.
  13.     The result is the address of the NUL byte that now terminates "dst".
  14.     Note that dst may safely be the same as src.
  15. */
  16.  
  17. #include "strings.h"
  18. #include "_str2set.h"
  19.  
  20. char *strcpack(dst, src, set, c)
  21.     register _char_ *dst, *src;
  22.     char *set;
  23.     register int c;
  24.     {
  25.         register int chr;
  26.  
  27.         _str2set(set);
  28.         while (chr = *src++) {
  29.             if (_set_vec[chr] != _set_ctr) {
  30.                 while ((chr = *src++) && _set_vec[chr] != _set_ctr) ;
  31.                 if (c) *dst++ = c;      /* 1. If you don't want trailing */
  32.                 if (!chr) break;        /* 2. things turned into "c", swap */
  33.             }                           /* lines 1 and 2. */
  34.             *dst++ = chr;
  35.         }
  36.         *dst = 0;
  37.         return dst;
  38.     }
  39.  
  40.